﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AI.Steering
{
    /// <summary>
    /// 到达
    /// </summary>
    public class SteeringForArrival : Steering
    {
        [Tooltip("减速半径")]
        public float slowDownDistance = 10;
        [Tooltip("到达半径")]
        public float arrivalDistance = 3;
        [Tooltip("目标物体变换组件")]
        public Transform targetTF;
        public override Vector3 GetForce()
        {
            //需要移动的距离
            float distance = Vector3.Distance(transform.position, targetTF.position) - arrivalDistance;
            //到达区：
            if (distance <= 0)
            {
                return Vector3.zero;
            }
            //减速区外：
            float readSpeed = speed;
            //减速区内：
            if (distance <= slowDownDistance)
            {
                readSpeed = (distance / slowDownDistance) * speed;
            }
            //期望力 = 目标位置 -自身位置
            Vector3 expectForce = (targetTF.position - transform.position).normalized * readSpeed;
            //实际力 = 期望力 - 当前力
            return (expectForce - controller.currentForce) * weight;//权重越大，实际力到打最大越快
        }
    }
}

